package cn.tlb.xutilsdownload.contentshear;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.IOException;

import cn.tlb.xutilsdownload.R;
import cn.tlb.xutilsdownload.http.Const;
import cn.tlb.xutilsdownload.http.DefaultCommentCallback;

public class ShearActivity extends AppCompatActivity {

    private String tag = "ShearActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shear);
       }

    public void send(View view) {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
        sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"452999812@qq.com"});
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
    }

    public void sendImg(View view) {
        // an image uri
        Uri uri = Uri.parse("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png");
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
        sendIntent.setType("image/*");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
    }


    public void upload(View view) throws IOException {
        Toast.makeText(ShearActivity.this, "upload", Toast.LENGTH_SHORT).show();
//        InputStream open = getAssets().open("1.png");
        RequestParams params = new RequestParams(Const.LOCAL_HOTS+"/data/upload");
//        params.addBodyParameter("name", "zhangsan");
//        params.addBodyParameter("data", new String(bytes,"utf-8"));
        params.addBodyParameter("data", "new File(\"/mnt/share/Image/1.png\")");
        x.http().post(params, new DefaultCommentCallback());



//        new Thread(){
//            @Override
//            public void run() {
//                try {
//                    URL url = new URL(Const.LOCAL_HOTS+"/data/upload");
//                    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//                    urlConnection.setRequestMethod("POST");
//                    urlConnection.setDoInput(true);
//                    urlConnection.setDoOutput(true);
//                    urlConnection.setUseCaches(false);
//                    urlConnection.connect();
//
//                    OutputStream out = urlConnection.getOutputStream();
//                    StringBuffer sb = new StringBuffer("name=zhangsan&data=aaa")
//                            /*.append(new String(bytes,"utf-8"))*/;
//                    out.write("name=zhangsan&data=aaa".getBytes("utf-8"));
//                    out.flush();
//                    out.close();
//
//                } catch (MalformedURLException e) {
//                    e.printStackTrace();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }.start();
    }
}
